package cc.magicjson.scenario.implement.module.jdbc.template.response;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 响应码枚举
 */
@Getter
@AllArgsConstructor
public enum ResultCode {
    SUCCESS("200", "操作成功"),
    ERROR("500", "系统错误"),
    PARAM_ERROR("400", "参数错误"),
    DATA_NOT_FOUND("404", "数据不存在"),
    DUPLICATE_KEY("409", "数据已存在"),
    BATCH_OPERATION_FAILED("4001", "批量操作失败"),
    DATABASE_ERROR("5001", "数据库操作错误"),
    TRANSACTION_ERROR("5002", "事务处理错误");

    private final String code;
    private final String description;

    public static ResultCode fromCode(String code) {
        for (ResultCode resultCode : ResultCode.values()) {
            if (resultCode.getCode().equals(code)) {
                return resultCode;
            }
        }
        return ERROR;
    }
}
